package reco.db.validation;

import reco.db.Constraint;

import com.google.common.base.Preconditions;

public class MaxConstraintFactory<E extends Comparable<E>> extends SimpleConstraintFactory implements DateConstraintFactory, NumberConstraintFactory {
    private final E max;

    public MaxConstraintFactory(E constraintMax) {
        super(expectedTypeOn(constraintMax));
        this.max = constraintMax;
    }

    private static final Class<?> expectedTypeOn(Comparable<?> constraintMax) {
        Preconditions.checkNotNull(constraintMax, "constraintMax");
        return constraintMax.getClass();
    }

    @Override
    protected <T> Constraint<T> createConstraint() {
        @SuppressWarnings("unchecked")
        final Constraint<T> constraint = (Constraint<T>) new MaxConstraint<E>(this.max);
        return constraint;
    }
}
